from typing import List
class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        slow = 0
        for i in range(len(nums)):
            if nums[i]!=0:
                nums[slow] = nums[i]
                slow+=1
        while slow < len(nums):
            nums[slow] = 0
            slow += 1

        return nums
        '''
            时间复杂度：O(N)
            空间复杂度：O(1)
        '''

    def moveZeroes2(self, nums: List[int]) -> None:
            """
            Do not return anything, modify nums in-place instead.
            """
            left = right = 0
            n = len(nums)
            while right < n:
                if nums[right] != 0:
                    nums[left], nums[right] = nums[right], nums[left]
                    left += 1
                right += 1
            return nums


        # print(Solution().moveZeroes([0,1,0,3,12]))
nums = [0,1,0,3,12]
# nums = [0]
print(Solution().moveZeroes(nums))